<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>收入结算</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/index.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-today">
    <p>￥0</p>
    <span>昨日结算(元)</span>
</div>
<div class="zz-top"></div>
<div class="zz-list">
    <ul>
        <li>
            <a class="zz-change-bank" href="javascript:;">
                <span class="zz-bank">结算银行</span>
                <span class="zz-right-arrow"></span>
                <span class="zz-replace"></span>
                <span class="zz-income-bank-name"></span>
            </a>
        </li>
    </ul>
</div>

<div class="zz-date-header">
    <ul class="zz-flex">
        <li class="zz-h88">收入日期</li>
        <li class="zz-h88">结算金额(元)</li>
        <li class="zz-h88">打款日期</li>
    </ul>

</div>
<div class="zz-date-list">
    <!--<div class="zz-time-price">
        <span class="zz-total-money">2017年2月</span>
        <span>总计￥1234.56</span>
    </div>
    <ul class="zz-flex">
        <li class="zz-h130">03-29 周四</li>
        <li class="zz-h130">
            <span class="zz-money-weight zz-padding-top">￥10.00</span>
            <span class="zz-bank-success">银行已打款</span>
        </li>
        <li class="zz-h130">
            <span class="zz-padding-top">03-29 周四</span>
            <span class="zz-bank-success flr">(8888)</span>
            <span class="zz-bank-success flr zz-max-name">民生银行</span>
        </li>
    </ul>-->
</div>

<input type="button" class="zz-look-more" value="没有更多了"/>
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>
<script charset="utf-8" type="text/javascript">
    var queryURLParameter = utils.queryURLParameter();
    var storeId = queryURLParameter.storeId;
    var pageSize = 20;
    var currentPage = 1;
    var total = [];
    var lastMonth = '';
    var lastDay = '';
    var $dateList = $(".zz-date-list");
    var $lookMore = $(".zz-look-more");

    //绑卡信息接口
    $.ajax({
        url: utils.ajaxUrl()+"h5/settlementController/queryEdrewInfByMerId",
        async: false,
        type: 'get',
        success: function (res) {
        	var res = JSON.parse(res);
        	//console.log(res);
            if (res && res.retCode == '0000') {
                var data = res["EdrawInfReData"];
                $(".zz-income-bank-name").html(data.bankName);
                var bankAccount = data.bankAccount;
                var bankCard = bankAccount.slice(bankAccount.length - 4, bankAccount.length);
                $(".zz-replace").html("(" + bankCard + ")");
                $(".zz-change-bank").attr("href", "../../html/h5/changeCard.html");
            }else{
                new $.modal({
                    content: res.retMsg,//弹框内容
                    showcontent: true,//false为弹出框组件二，true为弹出框组件一
                }).show();
            }
        }
    });

    //结算列表数据接口
    function bindDay(total, listDay) {
        //列表整体html
        var tempHtml = '';
        //月份html
        var sT = '';
        //月份的详细html
        var sL = '';

        for (var i = 0; i < total.length; i++) {
        	var curTotal = total[i];
        	var month = curTotal["month"].slice(0,4) + "年" + curTotal["month"].slice(4,6) + "月";
            sT = '<div class="zz-time-price">'
                    + '<span class="zz-total-money">' + month + '</span>'
                    + '<span>总计￥' + curTotal["amount"] + '</span>'
                    + '</div>';
            //如果符合条件相等，本次循环的内容添加到列表整体html
            var flag = false;
            //月内容的html拼接，只保留当前内层循环的html
            var sLHtml = '';
            for (var j = 0; j < listDay.length; j++) {
                var curDate = listDay[j];
                var tixiandate = '';
                var weektixian = '';
                var kahao = '';
                var bankName = '';
                var playMoney = '待打款';
                
                if(curDate["tixiandate"] != ""){
                	tixiandate = curDate["tixiandate"].slice(4).slice(0,2)+"-"+curDate["tixiandate"].slice(4).slice(2,4);
                	weektixian = utils.week(curDate["tixiandate"]);
                	kahao = '(' + curDate["kahao"].slice(curDate["kahao"].length - 4) + ')';
                	bankName = curDate["bankName"]；
                	playMoney = "银行已打款";
                }
                
                var date = curDate["date"].slice(4).slice(0,2)+"-"+curDate["date"].slice(4).slice(2,4);
                //var tixiandate = curDate["tixiandate"].slice(4).slice(0,2)+"-"+curDate["tixiandate"].slice(4).slice(2,4);
                var weekDay = utils.week(curDate["date"]);
                //var weektixian = utils.week(curDate["tixiandate"]);
                if (total[i]["month"] == listDay[j]["date"].slice(0, 6)) {
                    sL = '<ul class="zz-flex zz-date-week" date="' + listDay[listDay.length - 1]["date"] + '">'
                            + '<li class="zz-h130">' + date + " " + weekDay + '</li>'
                            + '<li class="zz-h130">'
                            + '<span class="zz-money-weight zz-padding-top">￥' + curDate["amt"] + '</span>'
                            + '<span class="zz-bank-success">'+ playMoney +'</span>'
                            + '</li>'
                            + '<li class="zz-h130">'
                            + '<span class="zz-padding-top">' + tixiandate + " " + weektixian + '</span>'
                            + '<span class="zz-bank-success flr">' + kahao + '</span>'
                            + '<span class="zz-bank-success flr zz-max-name">' + bankName + '</span>'
                            + '</li>'
                            + '</ul>';
                    sLHtml = sLHtml + sL;
                    flag = true;
                }
            }
            if (flag == true) {
                tempHtml += sT;
                tempHtml += sLHtml;
                lastMonth = i;
                lastDay = j;
            }
        }
        $dateList.html(tempHtml);
    }

    bindHTML();
    dateListUl();
    function dateListUl() {
        $(".zz-date-list div").prev("ul").css("border", "none");
    }
    function bindHTML() {
        $.ajax({
            url: utils.ajaxUrl()+"h5/settlementController/presentation",
            async: false,
            data: {
                storeId: storeId,
                pageSize: pageSize,
                currentPage: currentPage
            },
            type: 'get',
            success: function (res) {
            	//console.log(res);
            	var res = JSON.parse(res);
        		//console.log(res);
                if (res && res.retCode == '0000') {
                    total = res.total;
                    var listDay = res.listDay;
                    //console.log(listDay);
                    if(listDay !=undefined && listDay.length == 20){
                    	$lookMore.removeAttr("disabled").val("加载更多");
                    } else{
                    	$lookMore.attr("disabled", "true").val("没有更多了");
                    }
                    var firstAry = listDay.slice(0, 1);
                    if(firstAry[0]["date"] ==utils.getDateStr(-1)){
                        var firstDay = listDay.splice(0, 1);
                        $(".zz-today p").html("￥"+firstDay[0]["amt"]);
                    }else{
                        $(".zz-today p").html("￥0");
                    }
                    
                    bindDay(total, listDay);
                }else{
                    new $.modal({
                        content: res.retMsg,//弹框内容
                        showcontent: true,//false为弹出框组件二，true为弹出框组件一
                    }).show();
                    $lookMore.attr("disabled", "true").val("没有更多了");
                }
            }
        });
    }

    $(".zz-look-more").click(function () {
        currentPage++;
        $dateList.children("ul:last-child").css("border-bottom", "1px solid #dcdcdc");
        bindHTMLMore();
        dateListUl();
    });

    function bindDayMore(lastMonth, lastDay, listDay) {
        //列表整体html
        var oldDate = $dateList.children("ul:last-child").attr("date").slice(0, 6);
        var tempHtml = '';
        //月份html
        var sT = '';
        //月份的详细html
        var sL = '';
        var oneCount = 0;
        for (var k = lastMonth; k < total.length; k++) {
        	var curTotal = total[k];
        	var month = curTotal["month"].slice(0,4) + "年" + curTotal["month"].slice(4,6) + "月";
            sT = '<div class="zz-time-price">'
                    + '<span class="zz-total-money">' + month + '</span>'
                    + '<span>总计￥' + curTotal["amount"] + '</span>'
                    + '</div>';
            //如果符合条件相等，本次循环的内容添加到列表整体html
            var flag = false;
            //月内容的html拼接，只保留当前内层循环的html
            var sLHtml = '';
            //判断是否是第一次进入
            var oneFlag = false;
            for (var l = 0; l < listDay.length; l++) {
                var curDate = listDay[l];
                var tixiandate = '';
                var weektixian = '';
                var kahao = '';
                var bankName = '';
                var playMoney = '待打款';
                
                if(curDate["tixiandate"] != ""){
                	tixiandate = curDate["tixiandate"].slice(4).slice(0,2)+"-"+curDate["tixiandate"].slice(4).slice(2,4);
                	weektixian = utils.week(curDate["tixiandate"]);
                	kahao = '(' + curDate["kahao"].slice(curDate["kahao"].length - 4) + ')';
                	bankName = curDate["bankName"];
                	playMoney = "银行已打款";
                }
                
                var date = curDate["date"].slice(4).slice(0,2)+"-"+curDate["date"].slice(4).slice(2,4);
                //var tixiandate = curDate["tixiandate"].slice(4).slice(0,2)+"-"+curDate["tixiandate"].slice(4).slice(2,4);
                var weekDay = utils.week(curDate["date"]);
                //var weektixian = utils.week(curDate["tixiandate"]);
                if (total[k]["month"] == listDay[l]["date"].slice(0, 6)) {
                    sL = '<ul class="zz-flex zz-date-week" date="' + curDate["date"] + '">'
                            + '<li class="zz-h130">' + date + " " + weekDay + '</li>'
                            + '<li class="zz-h130">'
                            + '<span class="zz-money-weight zz-padding-top">￥' + curDate["amt"] + '</span>'
                            + '<span class="zz-bank-success">' + playMoney + '</span>'
                            + '</li>'
                            + '<li class="zz-h130">'
                            + '<span class="zz-padding-top">' + tixiandate + " " + weektixian + '</span>'
                            + '<span class="zz-bank-success flr">' + kahao + '</span>'
                            + '<span class="zz-bank-success flr zz-max-name">' + bankName + '</span>'
                            + '</li>'
                            + '</ul>';
                    sLHtml = sLHtml + sL;
                    flag = true;
                    if (oldDate == curDate["date"].slice(0, 6) && oneCount == 0) {
                        oneFlag = true;
                        oneCount = 1;
                    }
                }
            }
            if (oneFlag == true && flag == true) {
                tempHtml += sLHtml;
            } else if (flag == true) {
                tempHtml += sT;
                tempHtml += sLHtml;
            }
        }
        $dateList.append(tempHtml);
    }

    function bindHTMLMore() {
        $.ajax({
            url: utils.ajaxUrl()+"h5/settlementController/querySettlePage",
            async: false,
            data: {
                storeId: storeId,
                pageSize: pageSize,
                currentPage: currentPage
            },
            type: 'get',
            success: function (res) {
            	var res = JSON.parse(res);
        		//console.log(res);
                if (res && res.retCode == '0000') {
                    var listDay = res.listDay;
                    if(listDay && listDay.length == 20){
                    	$lookMore.removeAttr("disabled").val("加载更多");
                    } else{
                    	$lookMore.attr("disabled", "true").val("没有更多了");
                    }
                    
                    bindDayMore(lastMonth, lastDay, listDay);
                }else{
                    new $.modal({
                        content: res.retMsg,//弹框内容
                        showcontent: true,//false为弹出框组件二，true为弹出框组件一

                    }).show();
                }
            }
        });
    }

</script>
</html>